<?php
/**
 * Prepares a minimalist framework for unit testing.
 *
 * Joomla is assumed to include the /unittest/ directory.
 * eg, /path/to/joomla/unittest/
 *
 * @package     Joomla.UnitTest
 *
 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 * @link        http://www.phpunit.de/manual/current/en/installation.html
 */

define('_JEXEC', 1);

// Fix magic quotes.
@ini_set('magic_quotes_runtime', 0);

// Maximise error reporting.
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', 1);

/*
 * Ensure that required path constants are defined.  These can be overridden within the phpunit.xml file
 * if you chose to create a custom version of that file.
 */
if (!defined('JPATH_TESTS'))
{
	define('JPATH_TESTS', realpath(__DIR__));
}
if (!defined('JPATH_BASE'))
{
	define('JPATH_BASE', dirname(realpath(JPATH_TESTS)));
}
if (!defined('JPATH_PLATFORM'))
{
	define('JPATH_PLATFORM', JPATH_BASE . '/libraries');
}
if (!defined('JPATH_ROOT'))
{
	define('JPATH_ROOT', JPATH_BASE);
}
if (!defined('JPATH_CACHE'))
{
	define('JPATH_CACHE', JPATH_BASE . '/cache');
}
if (!defined('JPATH_CONFIGURATION'))
{
	define('JPATH_CONFIGURATION', JPATH_BASE);
}
if (!defined('JPATH_MANIFESTS'))
{
	define('JPATH_MANIFESTS', JPATH_BASE . '/manifests');
}
if (!defined('JPATH_PLUGINS'))
{
	define('JPATH_PLUGINS', JPATH_BASE . '/plugins');
}
if (!defined('JPATH_THEMES'))
{
	define('JPATH_THEMES', JPATH_BASE . '/themes');
}
if (!defined('JPATH_COMPONENT'))
{
	define('JPATH_COMPONENT', JPATH_BASE . '/components/com_browserempire');
}

// Import the platform.
require_once JPATH_PLATFORM . '/import.php';
require_once JPATH_PLATFORM . '/joomla/database/database.php';
require_once JPATH_PLATFORM . '/joomla/database/table.php';

// Register the core Joomla test classes.
//JLoader::registerPrefix('Test', __DIR__ . '/core');

// Some classes still dependen on JVersion
// until that's fixed we need to load it
require_once __DIR__ . '/version.php';

// Define configuration

jimport( 'joomla.registry.registry' );

require_once( JPATH_CONFIGURATION.'/configuration.php' );

$config = new JConfig();

// Get the global configuration object

$registry =& JFactory::getConfig();

// Load the configuration values into the registry

$registry->loadObject($config);

$options = array ('driver' => $config->dbtype,

'host' => $config->host,

'user' => $config->user,

'password' => $config->password,

'database' => $config->db,

'prefix' => $config->dbprefix );

// Preload database with configuration

$db = JDatabase::getInstance( $options );

// import joomla controller library
jimport('joomla.application.component.controller');

//// die allgemeinen Klassen registieren
JLoader::register('BeController',	JPATH_COMPONENT . DS . 'controller.php');
JLoader::register('BeModel',			JPATH_COMPONENT . DS . 'model.php');
JLoader::register('BeTable',			JPATH_COMPONENT . DS . 'table.php');

JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');

//// Helper
JLoader::register('BeRouteHelper',	JPATH_COMPONENT . DS . 'helpers' . DS . 'route.php');

// We need this to test JSession
ob_start();
